package com.olddriver.crm.service.impl;

import com.olddriver.crm.domain.PaidList;
import com.olddriver.crm.mapper.ClientMapper;
import com.olddriver.crm.mapper.PaidListMapper;
import com.olddriver.crm.page.PageResult;
import com.olddriver.crm.query.QueryObject;
import com.olddriver.crm.service.IPaidListService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;

/**
 * Created by A on 2017/12/5.
 */
@Service
public class PaidListService implements IPaidListService{

    @Autowired
    private PaidListMapper paidListMapper;

    @Autowired
    private ClientMapper clientMapper;

    @Override
    public int insert(PaidList record,Long id) {

        return paidListMapper.insert(record,id);
    }

    @Override
    public PaidList selectByPrimaryKey(Long id) {
        return paidListMapper.selectByPrimaryKey(id);
    }

    @Override
    public List<PaidList> selectAll() {
        return null;
    }

    @Override
    public PageResult query(QueryObject qo) {
        int total = paidListMapper.queryTotal(qo);
        if (total == 0) {
            return new PageResult(total, Collections.emptyList());
        }
        return new PageResult(total, paidListMapper.queryRows(qo));
    }

    @Override
    public void pay(Long id) {
        Long empId = paidListMapper.selectInsuranceListById(id);
        Byte a = 1;
        clientMapper.updateStatus(empId,a);
        paidListMapper.pay(id);
    }
}
